// pages/other_miniapp/index.js
var app = getApp(),
    core = app.requirejs("core");

Page({
    data: {
        appid: '',
        path: '',
        available: true,
        show: false
    },
 
    onLoad: function (options) {

    },

    onShow: function () {
        console.log("available_mini", this.data.available);
        if (this.data.available) {
            this.getTabbar();
        }
    },

    // 获取tabbar
    getTabbar: function (){
        var that = this;

        core.get("index/tabbar", {}, function (res) {
            if (res.code == 0) {
                console.log("miniapp_res",res);
                var tabbar = res.info.tabbar.list;
                if (tabbar.length > 0) {
                    for (var i = 0; i < tabbar.length; i++) {
                        if (tabbar[i].type == "applets" && tabbar[i].appid) {
                            that.setData({
                                appid: tabbar[i].appid
                            })

                            that.jumpMini();
                            break;
                        }
                    };
                } else {
                    core.alert('没有获取到信息')
                }
            } else {
                core.alert(res.msg)
            }
        })
    },

    // 跳转小程序
    jumpMini: function () {
        var that = this;
        wx.navigateToMiniProgram({
            appId: that.data.appid,
            path: '',
            extraData: {
                foo: 'bar'
            },
            envVersion: 'release',
            success(res) {
                console.log('打开成功')
            }
        })
    },

    onHide: function () {
        this.setData({
            available: true,
            show: true
        })
    },
})